package com.sweet.lambda;

/**
 * lambda演变
 */
public class Main {
    // 2.2 静态内部类
    static class Like2 implements ILike {
        @Override
        public void say() {
            System.out.println("I like lambda2~");
        }
    }

    public static void main(String[] args) {
        ILike like = new Like1();
        like.say();

        like = new Like2();
        like.say();

        // 2.3 局部内部类
        class Like3 implements ILike {
            @Override
            public void say() {
                System.out.println("I like lambda3~");
            }
        }

        like = new Like3();
        like.say();

        // 2.4 匿名内部类 没有类的名称 必须借助接口或者父类
        like = new ILike() {
            @Override
            public void say() {
                System.out.println("I like lambda4~");
            }
        };
        like.say();

        // 2.5 lambda 简化
        like = () -> {
            System.out.println("I like lambda5~");
        };
        like.say();
    }

}

// 1.定义一个接口 仅有一个方法的接口 叫做函数式接口
interface ILike {
    // public abstract void say1();
    void say();
}

// 2.1 定义类实现接口
class Like1 implements ILike {

    @Override
    public void say() {
        System.out.println("I like lambda1~");
    }
}
